/**
 * Created by PengWei on 2018/8/2.
 */

namespace game {
    import BaseCommand = mengdao.BaseCommand;

    export class UpdateModalCommand extends BaseCommand {

        /** 更新模态的原因 */
        private _reasonMap: Map<EnumModalReason, number> = new Map<EnumModalReason, number>();

        public execute(data) {
            let reason: EnumModalReason = data as EnumModalReason;
            if (this._eventType == GameEvent.ADD_MODAL) {
                this.executeAddModal(reason);
            } else {
                this.executeRemoveModal(reason);
            }
        }

        /**
         * 添加模态
         * @param {game.EnumModalReason} reason 模态原因
         */
        private executeAddModal(reason: EnumModalReason): void {
            if (this._reasonMap.has(reason)) {
                this._reasonMap.set(reason, this._reasonMap.get(reason) + 1);
            } else {
                this._reasonMap.set(reason, 1);
            }
        }

        /**
         * 删除模态
         * @param {game.EnumModalReason} reason 模态原因
         */
        private executeRemoveModal(reason: EnumModalReason): void {
            if (this._reasonMap.has(reason)) {
                let val: number = this._reasonMap.get(reason);
                val--;
                val = Math.max(val, 0);
                this._reasonMap.set(reason, val);
            }
        }

        private updateModal():void{
            let totalCount = this.getTotalCount();
            if(totalCount>0){

            }else{

            }
        }

        private getTotalCount():number{
            let num = 0;
            this._reasonMap.forEach((value:number)=>{
                num += value;
            },this);
            return num;
        }

    }
}